﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace WebRequest.WebApplication.Controllers
{
    public class SteamController : ApiController
    {
        public HttpResponseMessage Get()
        {
            var message = new string('A', 200);
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Headers.TransferEncodingChunked = true;
            // 使用PushStreamContent来逐个字符输出
            response.Content = new PushStreamContent((stream, content, transportContext) =>
            {
                using (var writer = new StreamWriter(stream))
                {
                    foreach (char c in message)
                    {
                        writer.Write(c);
                        writer.Flush(); // 立即发送字符到客户端
                        System.Threading.Thread.Sleep(100); // 模拟延迟
                    }
                }
            });
            return response;
        }
    }
}
